﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nero_demo
{
    class LogHelper
    {
        public delegate void LogHandler(string logContent);

        public static void Init()
        {
            logWriter = new System.IO.StreamWriter(logPath, true);
        }

        public static void Record(string logContent)
        {
            string logStr = DateTime.Now.ToString() + " " + logContent + "\r\n";

            logWriter.Write(logStr);
            logWriter.Flush();

            // 发布日志事件
            logEvent(logStr);
        }


        public static event LogHandler logEvent;
        private static string logPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log.txt";
        private static System.IO.StreamWriter logWriter;
    }
}
